package com.admin.scroller.photoorvideo.holders;

import android.annotation.SuppressLint;
import android.content.Context;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.admin.scroller.photoorvideo.R;
import com.admin.scroller.photoorvideo.adapter.GridViewAdapter;
import com.admin.scroller.photoorvideo.beans.DatePhoto;
import com.admin.scroller.photoorvideo.beans.LocalPhoto;
import com.bumptech.glide.Glide;
import com.bumptech.glide.RequestManager;

/**
 * 列表展示fragment的列表适配器 的 holder
 */
public class PhotosHolder extends RecyclerView.ViewHolder {

    private RecyclerView imageViews;
    private TextView textView;
    @SuppressLint("StaticFieldLeak")
    private static RequestManager manager;
    @SuppressLint("StaticFieldLeak")
    private static Context mContext;
    private GridViewAdapter adapter;
    private static int itemType;

    private ChildGridHolder.OnImageItemClick onImageItemClick;

    public static PhotosHolder getHolder(Context context, ViewGroup parent,int type){
        View view = LayoutInflater.from(context).inflate(R.layout.layout_photo_item, parent, false);
        itemType=type;
        mContext=context;
        manager=Glide.with(context);
        return new PhotosHolder(view);
    }

    private PhotosHolder(View itemView) {
        super(itemView);
        imageViews = itemView.findViewById(R.id.rlv_item_images);
        textView = itemView.findViewById(R.id.tv_item_date);
    }

    public void setOnImageItemClick(ChildGridHolder.OnImageItemClick onImageItemClick) {
        this.onImageItemClick = onImageItemClick;
    }

    public void initData(DatePhoto localPhoto, int position){
            textView.setText(localPhoto.getDate());
            imageViews.setLayoutManager(new GridLayoutManager(mContext, 4));
            adapter = new GridViewAdapter(mContext, localPhoto.getLocalPhotos(),position);
            adapter.setOnImageItemClick(onImageItemClick);
            imageViews.setAdapter(adapter);
    }


}
